/**
 * 用户能力关联表
 */
$(function(){
	webUtils.nameSpace("wiseMen.platform.userAbilityRel");
	
	wiseMen.platform.userAbilityRel.add=function(grid,bt,gridDef){
		var ABILITYID=gridDef.params.queryDatas.ABILITYID;
		if(ABILITYID && ABILITYID!=-1){
			webUtils.userSelector({
				isSelectAll:true,
				onSelect:function(ds){
					var ids=[];
					$.each(ds,function(i,n){
						ids.push(n.id);
					});
					
					if(ids.length>0){
						$.post(ctx+"/userAbilityAct/addUserToAbility.do",{abilityId:ABILITYID,userIds:ids.join(",")},function(r){
							if(r.success){
								grid.bootstrapTable("refresh");
							}else{
								webUtils.error(r.msg);
							}
						},"json");
					}
				}
			});
		}else{
			webUtils.error("请选择具体的能力模型");
		}
	}
	
	wiseMen.platform.userAbilityRel.del=function(grid,rowIndex){
		var row = grid.bootstrapTable("getRowByIndex", rowIndex);
		webUtils.confirm("删除数据将不可恢复，是否继续！",function(r){
			if(r){
				$.post(ctx + "/formDataAction/delByIds.do", {tableName:"PF_USER_ABILITY_REL",ids: row.ID}, function (data) {
	                if (data.success) {
	                	grid.bootstrapTable("refresh");
	                } else {
	                	webUtils.error(data.msg);
	                }
	            }, 'json');
			}
		});
	}
});